package controller

import (
	"gitee.com/huangxinbo/xcas/internal/app/base"
	"gitee.com/huangxinbo/xcas/internal/constants"
	"gitee.com/huangxinbo/xcas/internal/model"
	"gitee.com/huangxinbo/xcas/pkg"
	"gitee.com/huangxinbo/xcas/pkg/response"
	"github.com/gin-gonic/gin"
)

type AppController struct {
	base *base.Base
}

func NewAppController(base *base.Base) *AppController {
	return &AppController{
		base: base,
	}
}

func (c *AppController) RegisterRoutes(router *gin.Engine) {
	userGroup := router.Group("/api/app")
	{
		userGroup.GET("/health", c.HealthCheck)
		userGroup.GET("/config", c.AppConfig)
	}
}

// HealthCheck Health check
//
//	@Summary		Health check
//	@Description	Check if the service is running normally
//	@Tags			app
//	@Accept			json
//	@Produce		json
//	@Success		200	{object}	model.Response	"Service is running normally"
//	@Router			/api/app/health [get]
func (c *AppController) HealthCheck(ctx *gin.Context) {
	response.Success[any](ctx, c.base.I18n.T("Success"), nil)
}

// Get App Config
//
//	@Summary		Get App Config
//	@Description	Get application configure
//	@Tags			app
//	@Accept			json
//	@Produce		json
//	@Success		200	{object}	model.AppConfigResponse	"Get application configure"
//	@Router			/api/app/config [get]
func (c *AppController) AppConfig(ctx *gin.Context) {
	response.Success(ctx, c.base.I18n.T("Success"), model.AppConfigResponseData{
		Version:     pkg.GetEnvString("SERVER.VERSION", ""),
		Name:        pkg.GetEnvString("SERVER.NAME", ""),
		Logo:        constants.LOGO,
		Description: pkg.GetEnvString("SERVER.DESCRIPTION", ""),
	})
}
